package com.example.userService.controller;

import com.example.jwt.JwtUtil;
import com.example.userService.model.Users;
import com.example.userService.service.IUsersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RestController
@RequestMapping("/users")
@Slf4j
public class UsersController {
    IUsersService usersService;

    public UsersController(IUsersService usersService) {
        this.usersService = usersService;
    }

    @RequestMapping(value = "getList", method = RequestMethod.GET)
    public List<Users> update_account() {
        return  usersService.list();
    }

    @RequestMapping(value = "getById", method = RequestMethod.GET)
    public Users getById(@RequestParam("id") Long id) {
        return  usersService.getById(id);
    }

    @RequestMapping(value = "gets", method = RequestMethod.GET)
    public String gets() {
        return  "usersService.list()";
    }

    @RequestMapping(value = "getToken", method = RequestMethod.GET)
    public String getToken() {

        return JwtUtil.getJwtToken("admin","1");
    }


    @RequestMapping(value = "checkToken", method = RequestMethod.GET)
    public boolean checkToken(@RequestParam("token") String token) {
        log.info("token:"+token);
        return JwtUtil.checkToken(token);
    }

}
